/**
 * 接口：数据字典
 * @Author: 
 * @Date: 
 * @Copyright：
 */
import { postRequest, getRequest } from '/@/api/config/axios-fun';
import { ApiUtil } from "/@/utils/api";

export const MessageAPI = {
  init: () => ({
    id: 0,
    notifyUserId: null,
    title: null,
    content: null,
    notifyDate: null,
    displayFlag: null,
  }),
  listMessage(params) {
    return new Promise((resolve) => {
      getRequest("message/listMessage", params).then(({ res, data }) => {
        let list = [],
          pageIndex = 1,
          count = 0;
        if (ApiUtil.isResponseSuccess(data)) {
          list = data.data.data;
          if (data.data) {
            pageIndex = data.data.currentPage;
            count = data.data.count;
          }
        }
        resolve({ res, data, list, pageIndex, count });
      });
    });
  },

  deleteMessage(params, showMsgFlag = true, msg = '删除') {
    return new Promise((resolve) => {
      postRequest('message/deleteMessage', params, { inDataFlag: false }).then(({ res, data }) => {
        resolve({ ...ApiUtil.cleanGet({ res, data }, showMsgFlag, msg) });
      });
    });
  },

  updateMessage(params, showMsgFlag = true, msg = '修改') {
    return new Promise((resolve) => {
      postRequest('message/updateMessage', params).then(({ res, data }) => {
        resolve({ ...ApiUtil.cleanGet({ res, data }, showMsgFlag, msg) });
      });
    });
  },

  insertMessage(params, showMsgFlag = true, msg = '新增') {
    return new Promise((resolve) => {
      postRequest('message/insertMessage', params).then(({ res, data }) => {
        resolve({ ...ApiUtil.cleanGet({ res, data }, showMsgFlag, msg) });
      });
    });
  },

  getUserMessage(params) {
    return new Promise((resolve) => {
      getRequest('/message/getUserMessage', params).then(({ res, data }) => {
        resolve({ res, data });
      });
    });
  },
};
